#ifndef _IMAGE_SUBSET_H_
#define _IMAGE_SUBSET_H_

#include "math/vec2.h"

/***
 * @brief   Provides support for having multiple sub-images inside a \n
 * single texture. This is extemely usefull for particles, where you're 
 * wanting texture-animation without the texture swapping
 */

class ImageSubset
{
public:
    /***
    * @brief   Create a subset manager
    * @param    _Width  number of sub-images on horizontal axis
    * @param    _Height number of sub-images on Vertical axis
    * @param   _FrameTime time (in seconds) that a single frame takes
    */
                    ImageSubset(unsigned int _Width, unsigned int _Height, float _FrameTime);
                    ~ImageSubset();
    /***
    * @brief   Retrieve a given frame, based on time elapsed
    * @param    _Time   Time in seconds elapsed.
    * @param    _UV1    [out] top left corner of animation to use
    * @param    _UV2    [out] bottom right corner of animation to use
    */
    void            GetSubImage(float _Time, math::Vec2& _UV1, math::Vec2& _UV2);

    /***
    * @brief   Retrieve a given frame, based on frame ID
    * @param    _FrameID    ID of frame. Will wrap around
    * @param    _UV1    [out] top left corner of animation to use
    * @param    _UV2    [out] bottom right corner of animation to use
    */
    void            GetSubImage(unsigned int _FrameID, math::Vec2& _UV1, math::Vec2& _UV2);

    void            SetFrameC(unsigned short _FrameC);
    unsigned short  GetFrameC() const { return m_FrameC; };
   
private:
    struct  FrameInfo
    {
        math::Vec2  UV1, UV2;
    };
    FrameInfo*      GetFrame(unsigned short _X, unsigned short _Y);
    FrameInfo*      m_FrameA;
    unsigned short  m_Width, m_Height;
    unsigned short  m_FrameC;
    float           m_FrameTime;
};

#endif //_IMAGE_SUBSET_H_